package com.hehe.controller;

import com.hehe.POJO.T_user;
import com.hehe.Repository.T_User_Repository;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Optional;

@Controller
@RequestMapping(value = "")
public class Index {

    @Value("${config_file_name}")
    private String config_file_name;

    @Resource
    private T_User_Repository t_user_repository;


    //   不要带斜杠 / , Linux 下面会报错
    @GetMapping(value = "")
    public String index(Model model) {
        return "index.html";
    }

    //    ResponseBody
    //   不要带斜杠 / , Linux 下面会报错
    @GetMapping(value = "test")
    @ResponseBody
    public String ResponseBody_test(Model model) {
        return "ResponseBody----test---TEST----测试测试测试.....";
    }


    //   不要带斜杠 / , Linux 下面会报错
    @GetMapping(value = "user/{id}")
    @ResponseBody
    public String User(Model model, @PathVariable Long id  ) {
        Optional<T_user> user = t_user_repository.findById(id);
        return user.toString();
    }


    //   不要带斜杠 / , Linux 下面会报错
    @GetMapping(value = "all")
    @ResponseBody
    public String all_user(Model model) {
        List<T_user> all_user =  t_user_repository.findAll();
        return all_user.toString();
    }


}

